﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataInfo;
using KenLib.BusinessManager;
using KenLib.BusinessObject;
using System.Collections.Generic;

public partial class JOINT_frmJ_TraineeListSelect : System.Web.UI.Page
{
    応募情報Manager _応募情報Manager = new 応募情報Manager();
    事業内容Manager _事業内容Manager = new 事業内容Manager();

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Su kien form load
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        ((JOINT_MstPage_JOINT)this.Master).HideLiArea("frmJ_TraineeListSelect");
        ((JOINT_MstPage_JOINT)this.Master).changeTitle("候補者選択");

        ViewState["pageindex"] = 0;
        // Session["frmJ_TraineeSearch_Mode"] = ""Mode
        // Session["frmJ_TraineeSearch_Search"] = List TNS
        
        if (Session["frmJ_TraineeSearch_Search"] == null || Session["frmJ_TraineeSearch_Mode"] == null)
        {
            Response.Redirect("frmJ_TraineeSearch.aspx");
        }
        lbl_CongTy.Text = Session["frmJ_TraineeSearch_ddl_組合員企業選択_Text"].ToString();
        if (!IsPostBack)
        {
            if (Session["frmJ_TraineeSearch_Mode"].ToString() == "update")
            {
                DataTable dtExists = new DataTable();
                dtExists = frmJ_TraineeSearch_CheckExists(Convert.ToDateTime(Session["frmJ_TraineeSearch_txt_面接日"]), Convert.ToInt32(Session["frmJ_TraineeSearch_ddl_組合選択"]), Convert.ToInt32(Session["frmJ_TraineeSearch_ddl_組合員企業選択"]));
                ViewState["listNo"] = new List<string>();
                ShowData();
                hdCount.Value = dtExists.Rows.Count.ToString();
                int int_temp = CountRowCheckWithNumberPage();
                hdCheck.Value = int_temp.ToString();
                hdPageIndex.Value = "0";
            }
            else if (Session["frmJ_TraineeSearch_Mode"].ToString() == "insert")
            {
                ViewState["listNo"] = new List<string>();
                ShowData();
                hdCount.Value = "0";
                int int_temp = CountRowCheckWithNumberPage();
                hdCheck.Value = int_temp.ToString();
                hdPageIndex.Value = "0";
            }
            else
            {
                Response.Redirect("frmJ_TraineeSearch.aspx");
            }
            
        }

    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Them nhung dong duoc chon vao list
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_確認_Click(object sender, EventArgs e)
    {
        //if (TestCheckBox() == false)
        //{
        //    string error = "候補者 " + GetError("ER00007");
        //    ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('" + error + "');</script>");
        //    return;
        //}
        DataTable dt = ConvertToDataTableTemp();
        DataTable dtExists = new DataTable();
        dtExists = frmJ_TraineeSearch_CheckExists(Convert.ToDateTime(Session["frmJ_TraineeSearch_txt_面接日"]), Convert.ToInt32(Session["frmJ_TraineeSearch_ddl_組合選択"]), Convert.ToInt32(Session["frmJ_TraineeSearch_ddl_組合員企業選択"]));
        if (hdCount.Value == "0")
        {
            string error = "候補者が" + GetError("ER00007");
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('" + error + "');</script>");
            return;
        }
        else
        {
            List<string> listNo = (System.Collections.Generic.List<string>)ViewState["listNo"];
            if (Session["frmJ_TraineeSearch_Mode"].ToString() == "update")
            {
                if (Session["frmJ_TraineeListSelect_flagindex"]==null)
                {
                    List<string> listChild = new List<string>();
                    listChild = ConvertDataTableExistsToList(dt, dtExists);
                    listNo = ConvertListToList(listNo, listChild);
                }
                //ViewState["listNo"] = listNo;
            }
            foreach (GridViewRow row in grv.Rows)
            {
                CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
                Label temp = (Label)row.FindControl("lblNo");
                int index = Check(listNo, temp.Text);
                if (cb.Checked)
                {
                    if (index == -1)
                    {
                        listNo.Add(temp.Text);
                    }
                }
                else
                {
                    if (index != -1)
                    {
                        listNo.RemoveAt(index);
                    }
                }
            }

            foreach (GridViewRow row in grv.Rows)
            {
                if (row.RowIndex > -1)
                {
                    //DataTable dt = ConvertToDataTableTemp();

                    int pageindex = Convert.ToInt32(ViewState["pageindex"]);
                    int rows = 0;
                    int i = row.RowIndex;

                    rows = 10 * (pageindex) + i;
                    if (checkexist(dt, rows))
                    {
                        CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
                        cb.Checked = true;
                    }
                    else
                    {
                        CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
                        cb.Checked = false;
                    }
                }
            }

            ViewState["listNo"] = listNo;

            Session["frmJ_TraineeListSelect"] = GetSession();
            Response.Redirect("frmJ_TraineeListSelectCheck.aspx");
        }

    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Kiem tra dong nay da ton tai hay chua dua vao dropdowlist
    /// </summary>
    /// <returns></returns>
    public bool TestCheckBox()
    {
        foreach (GridViewRow row in grv.Rows)
        {
            CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
            if (cb != null && cb.Checked)
            {
                return true;
            }
        }
        return false;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Quay ve form frmJ_TraineeSearch
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_候補者検索_Click(object sender, EventArgs e)
    {
        Response.Redirect("frmJ_TraineeSearch.aspx");
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Hien thi du lieu len gridview
    /// </summary>
    public void ShowData()
    {
        DataTable dt = new DataTable();
        DataTable dtExists = new DataTable();
        dtExists = frmJ_TraineeSearch_CheckExists(Convert.ToDateTime(Session["frmJ_TraineeSearch_txt_面接日"]), Convert.ToInt32(Session["frmJ_TraineeSearch_ddl_組合選択"]), Convert.ToInt32(Session["frmJ_TraineeSearch_ddl_組合員企業選択"]));
        dt = ConvertToDataTableTemp();
        if (dt.Rows.Count == 0)
        {
            string strHeader = "No,登録年月日,氏名,性別,年齢,身長,体重,視力,最終学歴,在学状態,就業経験有無,経験作業名1,経験作業名2,経験作業名3,具体的仕事内容,日本語学習経験,現住所,出身地";
            ShowGridViewNotClassEmpty(grv, strHeader, "データがありません。");
        }
        else
        {
            hdCountGrv.Value = dt.Rows.Count.ToString();
            grv.DataSource = dt;
            grv.DataBind();
            CheckedRowExists(dtExists, dt);
            //lblCount.Text = dt.Rows.Count.ToString();
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Hien thi gridview rong
    /// </summary>
    /// <param name="grv"></param>
    /// <param name="strTableHeader"></param>
    /// <param name="strEmpty"></param>
    public void ShowGridViewNotClassEmpty(GridView grv, string strTableHeader, string strEmpty)
    {
        DataTable dt = new DataTable();
        string[] arrColumnNames = strTableHeader.Split(',');
        foreach (string str in arrColumnNames)
        {
            dt.Columns.Add(str);
        }
        grv.ShowFooter = false;
        DataRow r = dt.NewRow();
        dt.Rows.InsertAt(r, 0);
        grv.DataSource = dt;
        grv.DataBind();
        grv.Rows[0].Cells.Clear();
        TableCell cell = new TableCell();
        cell.ColumnSpan = grv.Columns.Count + 1;
        cell.Text = strEmpty;
        grv.Rows[0].Cells.Add(cell);

    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Chuyen doi chuoi
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public string Convert性別(string str)
    {
        string strtemp;
        if (str == "True")
        {
            strtemp = "Nữ";
        }
        else
        {
            strtemp = "Nam";
        }
        return strtemp;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Chuyen ngay thang sang tuoi
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public string Conver年齢(string str)
    {
        string temp = "";
        if (str == "")
        {
            temp = "";
            return temp;
        }
        DateTime dtDate = DateTime.Parse(str);
        int tuoi = DateTime.Now.Year - dtDate.Year;
        if (DateTime.Now.Month < dtDate.Month)
        {
            tuoi--;
        }
        else if (DateTime.Now.Month == dtDate.Month && DateTime.Now.Day < dtDate.Day)
        {
            tuoi--;
        }
        return Convert.ToString(tuoi);
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Chuyen doi chuoi
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public string Convert就業経験有無(string str)
    {

        if (str == "")
        {
            str = "";
        }
        else if (Convert.ToBoolean(str) == false)
        {
            str = "Không";
        }
        else
        {
            str = "Có";
        }
        return str;
    }



    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Lay chuoi loi dua vao id
    /// </summary>
    /// <param name="errorid"></param>
    /// <returns></returns>
    public String GetError(string errorid)
    {
        string error = "";
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        if (dt.Rows.Count > 0)
        {
            error = dt.Rows[0][2].ToString();
        }
        return error;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Chuyen doi chuoi
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public string Convert日本語学習経験(string temp)
    {
        string str_Result = "";
        switch (temp)
        {
            case "1":
                str_Result = "Dưới 3 tháng";
                break;
            case "2":
                str_Result = "Trên 3 tháng";
                break;
            case "3":
                str_Result = "Trên 6 tháng";
                break;
            case "0":
                str_Result = "Không có";
                break;
            default:
                str_Result = "";
                break;
        }
        return str_Result;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Phan tran gridview
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        DataTable dt = ConvertToDataTableTemp();
        DataTable dtExists = new DataTable();
        dtExists = frmJ_TraineeSearch_CheckExists(Convert.ToDateTime(Session["frmJ_TraineeSearch_txt_面接日"]), Convert.ToInt32(Session["frmJ_TraineeSearch_ddl_組合選択"]), Convert.ToInt32(Session["frmJ_TraineeSearch_ddl_組合員企業選択"]));
        List<string> listNo = (System.Collections.Generic.List<string>)ViewState["listNo"];
        if (Session["frmJ_TraineeSearch_Mode"].ToString() == "update")
        {
            List<string> listChild = new List<string>();
            listChild = ConvertDataTableExistsToList(dt, dtExists);
            listNo = ConvertListToList(listNo, listChild);
            //ViewState["listNo"] = listNo;
        }
        foreach (GridViewRow row in grv.Rows)
        {
            CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
            Label temp = (Label)row.FindControl("lblNo");
            int index = Check(listNo, temp.Text);
            if (cb.Checked)
            {
                if (index == -1)
                {
                    listNo.Add(temp.Text);
                }
            }
            else
            {
                if (index != -1)
                {
                    listNo.RemoveAt(index);
                }
                CheckBox cb1 = (CheckBox)grv.HeaderRow.FindControl("ckb_全て選択");
                cb1.Checked = false;
            }
        }
        Session["frmJ_TraineeListSelect_flagindex"] = "1";
        ViewState["listNo"] = listNo;
        ViewState["pageindex"] = e.NewPageIndex;
       
        hdPageIndex.Value = e.NewPageIndex.ToString();
        grv.PageIndex = e.NewPageIndex;
        ShowData();
    }


    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Tim vi tri trong list
    /// </summary>
    /// <param name="list"></param>
    /// <param name="label"></param>
    /// <returns></returns>
    public int Check(List<string> list, string label)
    {
        int temp = -1;
        for (int i = 0; i < list.Count; i++)
        {
            if (list[i] == label)
            {
                temp = i;
                break;
            }

        }
        return temp;
    }


    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Chuyen tu datatable sang databale
    /// </summary>
    /// <returns></returns>
    public DataTable ConvertToDataTableTemp()
    {
        DataTable dt1 = new DataTable();
        dt1 = (DataTable)Session["frmJ_TraineeSearch_Search"];//chuyen o day
        DataTable dt = new DataTable();
        if (dt1.Rows.Count > 0)
        {
            dt.Columns.Add("No", typeof(string));
            dt.Columns.Add("登録年月日", typeof(string));
            dt.Columns.Add("氏名", typeof(string));
            dt.Columns.Add("性別", typeof(string));
            dt.Columns.Add("年齢", typeof(string));
            dt.Columns.Add("身長", typeof(string));
            dt.Columns.Add("体重", typeof(string));
            dt.Columns.Add("視力", typeof(string));
            dt.Columns.Add("最終学歴", typeof(string));
            dt.Columns.Add("在学状態", typeof(string));
            dt.Columns.Add("就業経験有無", typeof(string));
            dt.Columns.Add("経験作業名1", typeof(string));
            dt.Columns.Add("経験作業名2", typeof(string));
            dt.Columns.Add("経験作業名3", typeof(string));
            dt.Columns.Add("具体的仕事内容", typeof(string));
            dt.Columns.Add("日本語学習経験", typeof(string));
            dt.Columns.Add("現住所", typeof(string));
            dt.Columns.Add("出身地", typeof(string));
            dt.Columns.Add("Email", typeof(string));
            dt.Columns.Add("status", typeof(string));
            dt.Columns.Add("ID", typeof(string));


            for (int i = 0; i < dt1.Rows.Count; i++)
            {
                int temp = i + 1;
                string No = Convert.ToString(temp);
                string 登録年月日 = "";
                if (dt1.Rows[i]["登録年月日"].ToString() != "")
                {
                    登録年月日 = String.Format("{0:yyyy年MM月dd日}", Convert.ToDateTime(dt1.Rows[i]["登録年月日"]));
                }
                else
                {
                    登録年月日 = "";
                }
                string 氏名 = dt1.Rows[i]["姓"].ToString() + " " + dt1.Rows[i]["名"].ToString();
                string 性別 = Convert性別(dt1.Rows[i]["性別"].ToString());
                string 年齢 = Conver年齢(dt1.Rows[i]["生年月日"].ToString()).ToString();
                string 身長 = dt1.Rows[i]["身長"].ToString();
                string 体重 = dt1.Rows[i]["体重"].ToString();

                string 視力 = "";
                switch (dt1.Rows[i]["視力"].ToString())
                {

                    case "0":
                        視力 = "Bình thường";
                        break;
                    case "1":
                        視力 = "Đeo kính";
                        break;
                    case "2":
                        視力 = "Đeo kính áp tròng";
                        break;
                    default:
                        視力 = "";
                        break;

                }


                string 最終学歴 = "";
                switch (dt1.Rows[i]["最終学歴"].ToString())
                {
                    case "0":
                        最終学歴 = "Tiến Sỹ";
                        break;
                    case "1":
                        最終学歴 = "Thạc Sỹ";
                        break;
                    case "2":
                        最終学歴 = "Cử Nhân";
                        break;
                    case "3":
                        最終学歴 = "Cao Đẳng";
                        break;
                    case "4":
                        最終学歴 = "Tốt nghiệp Phổ Thông";
                        break;
                    case "5":
                        最終学歴 = "Tốt nghiệp Trung Học";
                        break;
                    default:
                        最終学歴 = "";
                        break;
                }

                string 在学状態 = dt1.Rows[i]["在学学校名"].ToString();
                string 就業経験有無 = Convert就業経験有無(dt1.Rows[i]["就業経験有無"].ToString());
                string 経験作業名1 = dt1.Rows[i]["経験作業名1"].ToString();
                string 経験作業名2 = dt1.Rows[i]["経験作業名2"].ToString();
                string 経験作業名3 = dt1.Rows[i]["経験作業名3"].ToString();
                string 具体的仕事内容 = dt1.Rows[i]["具体的仕事内容"].ToString();
                string 日本語学習経験 = Convert日本語学習経験(dt1.Rows[i]["日本語学習経験"].ToString());
                string 現住所 = dt1.Rows[i]["現住所"].ToString();
                string 出身地 = dt1.Rows[i]["出身地"].ToString();
                string Email = dt1.Rows[i]["Email"].ToString();
                string ID = dt1.Rows[i]["ID"].ToString();
                string status = "0";
                dt.Rows.Add(No, 登録年月日, 氏名, 性別, 年齢, 身長, 体重, 視力, 最終学歴, 在学状態, 就業経験有無, 経験作業名1, 経験作業名2, 経験作業名3, 具体的仕事内容, 日本語学習経験, 現住所, 出身地, Email, status, ID);

            }
        }
        return dt;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Chuyen list sang datatable
    /// </summary>
    /// <returns></returns>
    public DataTable GetSession()
    {

        DataTable dt = new DataTable();
        dt.Columns.Add("No", typeof(string));
        dt.Columns.Add("登録年月日", typeof(string));
        dt.Columns.Add("氏名", typeof(string));
        dt.Columns.Add("性別", typeof(string));
        dt.Columns.Add("年齢", typeof(string));
        dt.Columns.Add("身長", typeof(string));
        dt.Columns.Add("体重", typeof(string));
        dt.Columns.Add("視力", typeof(string));
        dt.Columns.Add("最終学歴", typeof(string));
        dt.Columns.Add("在学状態", typeof(string));
        dt.Columns.Add("就業経験有無", typeof(string));
        dt.Columns.Add("経験作業名1", typeof(string));
        dt.Columns.Add("経験作業名2", typeof(string));
        dt.Columns.Add("経験作業名3", typeof(string));
        dt.Columns.Add("具体的仕事内容", typeof(string));
        dt.Columns.Add("日本語学習経験", typeof(string));
        dt.Columns.Add("現住所", typeof(string));
        dt.Columns.Add("出身地", typeof(string));
        dt.Columns.Add("Email", typeof(string));
        dt.Columns.Add("ID", typeof(string));
        int temp = 0;
        List<string> list = (System.Collections.Generic.List<string>)ViewState["listNo"];
        DataTable dt1 = ConvertToDataTableTemp();
        for (int i = 0; i < dt1.Rows.Count; i++)
        {
            for (int j = 0; j < list.Count; j++)
            {
                if (dt1.Rows[i]["No"].ToString() == list[j].ToString())
                {

                    temp = temp + 1;
                    string No = Convert.ToString(temp);
                    string 登録年月日 = dt1.Rows[i]["登録年月日"].ToString();
                    string 氏名 = dt1.Rows[i]["氏名"].ToString();
                    string 性別 = dt1.Rows[i]["性別"].ToString();
                    string 年齢 = dt1.Rows[i]["年齢"].ToString();
                    string 身長 = dt1.Rows[i]["身長"].ToString();
                    string 体重 = dt1.Rows[i]["体重"].ToString();
                    string 視力 = dt1.Rows[i]["視力"].ToString();
                    string 最終学歴 = dt1.Rows[i]["最終学歴"].ToString();
                    string 在学状態 = dt1.Rows[i]["在学状態"].ToString();
                    string 就業経験有無 = dt1.Rows[i]["就業経験有無"].ToString();
                    string 経験作業名1 = dt1.Rows[i]["経験作業名1"].ToString();
                    string 経験作業名2 = dt1.Rows[i]["経験作業名2"].ToString();
                    string 経験作業名3 = dt1.Rows[i]["経験作業名3"].ToString();
                    string 具体的仕事内容 = dt1.Rows[i]["具体的仕事内容"].ToString();
                    string 日本語学習経験 = dt1.Rows[i]["日本語学習経験"].ToString();
                    string 現住所 = dt1.Rows[i]["現住所"].ToString();
                    string 出身地 = dt1.Rows[i]["出身地"].ToString();
                    string Email = dt1.Rows[i]["Email"].ToString();
                    string ID = dt1.Rows[i]["ID"].ToString();

                    dt.Rows.Add(No, 登録年月日, 氏名, 性別, 年齢, 身長, 体重, 視力, 最終学歴, 在学状態, 就業経験有無, 経験作業名1, 経験作業名2, 経験作業名3, 具体的仕事内容, 日本語学習経験, 現住所, 出身地, Email, ID);
                }
            }
        }
        return dt;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Load lai tren girdview nhung dong da duoc chon truoc do
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex > -1)
        {
            DataTable dt = ConvertToDataTableTemp();

            int pageindex = Convert.ToInt32(ViewState["pageindex"]);
            int rows = 0;
            int i = e.Row.RowIndex;

            rows = 10 * (pageindex) + i;
            if (checkexist(dt, rows))
            {
                CheckBox cb = (CheckBox)e.Row.FindControl("CheckBox1");
                cb.Checked = true;
            }
            else
            {
                CheckBox cb = (CheckBox)e.Row.FindControl("CheckBox1");
                cb.Checked = false;
            }
        }
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Kiem tra dong nay da ton tai trong danh sach nhung dong duoc chon hay chua
    /// </summary>
    /// <param name="dt"></param>
    /// <param name="rows"></param>
    /// <returns></returns>
    private Boolean checkexist(DataTable dt, int rows)
    {

        List<string> list = (System.Collections.Generic.List<string>)ViewState["listNo"];
        for (int j = 0; j < list.Count; j++)
        {
            if (dt.Rows[rows]["No"].ToString() == list[j].ToString())
            {
                dt.Rows[rows]["status"] = "1";
                return true;
            }
        }

        return false;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Lay danh danh du lieu dua vao 経験作業名 cua bang 事業内容
    /// </summary>
    /// <param name="経験作業名"></param>
    /// <returns></returns>
    public DataTable frmJ_TraineeListSelect_事業内容(int 経験作業名)
    {
        DataTable dt = new DataTable();
        dt = _事業内容Manager.frmJ_TraineeListSelect_事業内容(経験作業名);
        return dt;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Neu chuoi dai hon 20 ky se cat ra theo dang aaaaaaaa...
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string ShowTextLength(string temp)
    {
        //tieng viet
        if (temp.Length > 20)
        {
            temp = temp.Substring(0, 20) + "...";
        }
        return temp;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Noi dung: Neu chuoi dai hon 30 ky se cat ra theo dang aaaaaaaa...
    /// </summary>
    /// <param name="temp"></param>
    /// <returns></returns>
    public string ShowTextLength1(string temp)
    {
        //tieng viet
        if (temp.Length > 30)
        {
            temp = temp.Substring(0, 30) + "...";
        }
        return temp;

    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check exists ID in table 面接情報
    /// </summary>
    /// <param name="面接日"></param>
    /// <param name="団体ID"></param>
    /// <param name="企業ID"></param>
    /// <returns></returns>
    public DataTable frmJ_TraineeSearch_CheckExists(DateTime 面接日, int 団体ID, int 企業ID)
    {
        DataTable dt = _応募情報Manager.frmJ_TraineeSearch_CheckExists応募情報(面接日, 団体ID, 企業ID);
        return dt;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Check exists row in datatable
    /// </summary>
    /// <param name="dt"></param>
    /// <param name="dtExists"></param>
    /// <returns></returns>
    public bool CheckRowExists(DataTable dt, string ID)
    {
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (dt.Rows[i]["ID"].ToString() == ID)
            {
                return true;
            }
        }
        return false;
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Checked row select in gridview
    /// </summary>
    /// <param name="dtExists"></param>
    /// <param name="dt"></param>
    public void CheckedRowExists(DataTable dtExists, DataTable dt)
    {
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (CheckRowExists(dtExists, dt.Rows[i]["ID"].ToString()))
            {
                foreach (GridViewRow row in grv.Rows)
                {
                    Label temp = (Label)row.FindControl("lblNo");
                    if (temp.Text == (i + 1).ToString())
                    {
                        CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
                        cb.Checked = true;
                    }
                }
            }
        }
    }

    
    /// <summary>
    /// Coder: Thanh Dong
    /// Function: Count row check in gridview with page indexs
    /// </summary>
    /// <returns></returns>
    public int CountRowCheckWithNumberPage()
    {
        int temp = 0;
        foreach (GridViewRow row in grv.Rows)
        {
            CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
            if (cb.Checked == true)
            {
                temp = temp + 1;
            }
        }
        return temp;
    }
    
    /// <summary>
    /// Coder: Thanh Dong
    /// Event: Page Index Changed
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void grv_PageIndexChanged(object sender, EventArgs e)
    {
        DataTable dt = ConvertToDataTableTemp();
        DataTable dtExists = new DataTable();
        dtExists = frmJ_TraineeSearch_CheckExists(Convert.ToDateTime(Session["frmJ_TraineeSearch_txt_面接日"]), Convert.ToInt32(Session["frmJ_TraineeSearch_ddl_組合選択"]), Convert.ToInt32(Session["frmJ_TraineeSearch_ddl_組合員企業選択"]));
        //List<string> listNo = (System.Collections.Generic.List<string>)ViewState["listNo"];
        //if (Session["frmJ_TraineeSearch_Mode"].ToString() == "update")
        //{
        //    List<string> listChild = new List<string>();
        //    listChild = ConvertDataTableExistsToList(dt, dtExists);
        //    listNo = ConvertListToList(listNo, listChild);
        //    //ViewState["listNo"] = listNo;
        //}
        //foreach (GridViewRow row in grv.Rows)
        //{
        //    CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
        //    Label temp = (Label)row.FindControl("lblNo");
        //    int index = Check(listNo, temp.Text);
        //    if (cb.Checked)
        //    {
        //        if (index == -1)
        //        {
        //            listNo.Add(temp.Text);
        //        }
        //    }
        //    else
        //    {
        //        if (index != -1)
        //        {
        //            listNo.RemoveAt(index);
        //        }
        //        CheckBox cb1 = (CheckBox)grv.HeaderRow.FindControl("ckb_全て選択");
        //        cb1.Checked = false;
        //    }
        //}

        int int_temp = 0;

        if (ViewState["pageindex"].ToString() == ((int)(dt.Rows.Count / 10)).ToString())
        {
            int_temp = CountRowCheckWithNumberPage();
            if (int_temp == dt.Rows.Count % 10)
            {
                CheckBox cb1 = (CheckBox)grv.HeaderRow.FindControl("ckb_全て選択");
                cb1.Checked = true;
            }
            else
            {
                CheckBox cb1 = (CheckBox)grv.HeaderRow.FindControl("ckb_全て選択");
                cb1.Checked = false;
            }
        }
        else
        {
            int_temp = CountRowCheckWithNumberPage();
            if (int_temp == 10)
            {
                CheckBox cb1 = (CheckBox)grv.HeaderRow.FindControl("ckb_全て選択");
                cb1.Checked = true;
            }
            else
            {
                CheckBox cb1 = (CheckBox)grv.HeaderRow.FindControl("ckb_全て選択");
                cb1.Checked = false;
            }
        }
        //ViewState["listNo"] = listNo;
        hdCheck.Value = int_temp.ToString();
        //ShowData();
    }

    /// <summary>
    /// Coder: Thanh Dong
    /// Function: If exists row from dt1, dt2. Add row to list
    /// </summary>
    /// <param name="dt"></param>
    /// <param name="dtExists"></param>
    /// <returns></returns>
    public List<string> ConvertDataTableExistsToList(DataTable dt, DataTable dtExists)
    {
        List<string> list = new List<string>();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (CheckRowExists(dtExists, dt.Rows[i]["ID"].ToString()))
            {
                list.Add((i+1).ToString());
            }
        }
        return list;
    }

    public List<string> ConvertListToList(List<string> listMaster, List<string> listChild)
    {

        if (listMaster.Count == 0)
        {
            listMaster = listChild;
        }
        else
        {
            for (int i = 0; i < listMaster.Count; i++)
            {
                for (int j = 0; j < listChild.Count; j++)
                {
                    if (CheckRowExistsList(listMaster, listChild[j].ToString()))
                    {
                        listMaster.Add(listChild[j].ToString());
                        listMaster.Sort();
                    }
                }
            }
        }
        
        return listMaster;
    }

    public bool CheckRowExistsList(List<string> list, string temp)
    {
        for (int i = 0; i < list.Count; i++)
        {
            if (list[i].ToString() == temp)
            {
                return false; 
            }
        }
        return true;
    }
}
